package string;

import java.util.Arrays;

/*字符串支持正则表达式方法二
String[] spilt(String regex)
将当前字符串按照满足正则表达式的部分进行拆分，返回的数组中包含被拆分出来的所有部分
 */
public class SpiltDemo {
    public static void main(String[] args) {
        String str ="adfsa1212sfdsa45454sdfas54dd";
        //按照数字部分进行拆分，得到所有的字母部分
        String[] data=str.split("[0-9]+");
        System.out.println(data.length);
        System.out.println(Arrays.toString(data));

        str="a,sdf,fdf,s,s,s";
        data=str.split(",");
        System.out.println(data.length);
        System.out.println(Arrays.toString(data));


        //连续遇到可拆分项，他们之间会拆出空串,若字符串一上来就遇到可拆分串
        str="a,sdf,fdf,,,s,s,s";
        data=str.split(",");
        System.out.println(data.length);
        System.out.println(Arrays.toString(data));

        //若字符串一上来就遇到可拆分串，则先拆分出一个空串。
        str=",a,sdf,fdf,,,s,s,s";
        data=str.split(",");
        System.out.println(data.length);
        System.out.println(Arrays.toString(data));

       //若字符串末尾出现可拆分串，则拆分处的空字符串会被忽略
        str=",a,sdf,fdf,,,s,s,s。,,,,,,,,";
        data=str.split(",");
        System.out.println(data.length);
        System.out.println(Arrays.toString(data));

        String x="la.dsfasf ...asfdsadf...";
        String[] b=x.split("\\.");
        System.out.println(b.length);
        System.out.println(Arrays.toString(b));


    }
}
